package com.elitel.frame.base.controller.protal;


import com.elitel.base.core.controller.BaseController;
import com.elitel.base.core.domain.AjaxResult;
import com.elitel.base.core.page.TableDataInfo;
import com.elitel.frame.base.service.jdpPortal.JdpPortalService;
import com.elitel.frame.main.entity.protal.JdpPortal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/jdpPortal/portal")
@RestController
public class JdpPortalController extends BaseController {

    @Autowired
    private JdpPortalService jdpPortalService;

    /**
     * 门户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JdpPortal jdpPortal) {
        startPage();
        List<JdpPortal> list = jdpPortalService.selectJdpPortalList(jdpPortal);
        return getDataTable(list);
    }

    /**
     * 根据门户编号获取详细信息
     */
    @GetMapping(value = "/{portalId}")
    public AjaxResult getInfo(@PathVariable String portalId) {
        return success(jdpPortalService.selectDataById(portalId));
    }

    /**
     * 新增门户信息
     */
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody JdpPortal jdpPortal) {
        if (!jdpPortalService.checkPortalIdUnique(jdpPortal)) {
            return error("新增参数'" + jdpPortal.getPortalId() + "'失败，门户已存在");
        }
        return toAjax(jdpPortalService.insertConfig(jdpPortal));
    }

    /**
     * 修改门户配置
     */
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody JdpPortal jdpPortal) {
        return toAjax(jdpPortalService.updateConfig(jdpPortal));
    }

    /**
     * 删除门户配置
     */
    @PostMapping("/remove/{portalIds}")
    public AjaxResult remove(@PathVariable String[] portalIds) {
        jdpPortalService.deleteConfigByIds(portalIds);
        return success();
    }

    /**
     * 复制门户配置
     */
    @PostMapping("/copy")
    public AjaxResult copy(@RequestParam("id") String id) {
        JdpPortal jdpPortal = jdpPortalService.selectDataById(id);
        if (jdpPortal == null) {
            return error("参数'" + id + "'有误，门户不存在");
        }
        return toAjax(jdpPortalService.copy(jdpPortal));
    }

    @PostMapping("/test")
    public AjaxResult test(@RequestParam("id") String id, @RequestParam("code") String code, @RequestBody JdpPortal jdpPortal) {
        System.out.println(id);
        System.out.println(code);
        System.out.println(jdpPortal);
        return success(jdpPortal);
    }

}
